package com.crr.service.impl;

import com.crr.bean.Employee;
import com.crr.common.crud.BaseServiceImpl;
import com.crr.mapper.EmployeeMapper;
import com.crr.mapper.UserMapper;
import com.crr.service.EmployeeService;
import com.crr.utils.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee, EmployeeMapper> implements EmployeeService {
    @Autowired
    UserMapper userMapper;

    /**
     * 如果方法中出现异常，事务回滚
     * @param entity 要保存的对象
     * @return
     */
    @Transactional//事务管理
    public int save(Employee entity){
        entity.getUser().setType(1);
        int res=userMapper.save(entity.getUser());
        Assert.isNotSuccess(res,"用户保存失败");
        return super.save(entity);
    }

}
